var express = require('express');
var swig = require('swig');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');

var app = express();

app.use('/public', express.static('public'));

app.engine('html', swig.renderFile);
// 渲染的目录
app.set('views', './views');
app.set('view engine', 'html');
//在开发过程中，需要取消模板缓存
swig.setDefaults({cache: false});

app.use(bodyParser.json());
//bodyparser设置
app.use(bodyParser.urlencoded({extended: true}));

app.use('/admin', require('./routers/admin'));
app.use('/api', require('./routers/api'));
app.use('/', require('./routers/main'));


mongoose.connect('mongodb://localhost:27017/blog',{useNewUrlParser:true}, function (err, doc) {
  if (err) {
    throw err
  } else {
    console.log('链接成功');
    var server = app.listen(3000, '192.168.0.11', function () {
      var host = server.address().address;
      var port = server.address().port;
      console.log('Example app listening at http://%s:%s', host, port);
    });
  }
})

